package hkr.vfu.bluecenter.backend;

import java.util.*;

/**
 * Created by mattias on 12/12/13.
 */
public class DataSingleton {

    private static DataSingleton instance;
    //HashMap containing all the registers boxes settings. The key is the MAC address.
    private HashMap<String, BoxVO> boxVOHashMap;


    private DataSingleton() {

    }

    public static DataSingleton getInstance() {
        if (instance == null) instance = new DataSingleton();
        return instance;
    }

    public boolean addBox(String MAC, BoxVO box) {
        if (!boxVOHashMap.containsKey(MAC)) {
            boxVOHashMap.put(MAC, box);
            return true;
        }
        return false;
    }

    public boolean containsBox(String MAC) {
        return boxVOHashMap.containsKey(MAC);
    }

    public BoxVO getBoxWithMAC(String MAC) {
        return boxVOHashMap.get(MAC);
    }

    public boolean setLatestValues(int[] values, String MAC) {
        SensorVO[] sensorVOs = boxVOHashMap.get(MAC).getSensors();
        if (values.length == sensorVOs.length) {
            for (int i = 0; i < sensorVOs.length; i++) {
                sensorVOs[i].setValue(values[i], new Date());
            }
            return true;
        }
        return false;
    }

    public HashMap<String, BoxVO> getHashMap() {
        return boxVOHashMap;
    }


    public void setHashMap(HashMap<String, BoxVO> hashMap) {
        this.boxVOHashMap = hashMap;
    }
}
